package com.icode.dao.impl;

import com.icode.core.model.house.HouseBaseArea;
import com.icode.core.model.manage.SellManager;
import com.icode.dao.SellManagerDao;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-8-15
 * Time: 上午10:50
 * To change this template use File | Settings | File Templates.
 */
@Repository("sellManagerDao")
public class SellManagerDaoImpl extends EntityDaoImpl implements SellManagerDao {

    @Override
    public List<SellManager> findSellManagerByAll() {
        String hql = "from " + SellManager.class.getName();
        Query query = currentSession().createQuery(hql);
        return query.list();
    }

    @Override
    public SellManager findSellIsExist(String area) {
        String hql = "from " + SellManager.class.getName() + " a where a.houseBaseArea=:area";
        Query query = currentSession().createQuery(hql);
        query.setParameter("area", HouseBaseArea.valueOf(area));
        List<SellManager> list = query.list();
        return list.isEmpty() ? null : list.get(0);
    }
}
